{% extends "base.html" %}

{% block extra_head %}
{{ form.media.css }}
<script>
  function getRequest(method, url) {
    request = new XMLHttpRequest();
    request.open(method, url);
    request.setRequestHeader("Content-type","application/json");
    request.setRequestHeader("Authorization","Token {{user.auth_token.key}}");
    return request;
  }

  function deleteRevision(target) {
    const button = target;
    const revisionId = target.getAttribute('data-id');
    request = getRequest('DELETE', `/api/installers/revisions/${revisionId}`);
    request.onreadystatechange = function() {
      console.log('Revision deleted');
    };
    request.send();
  }
</script>
{% endblock extra_head %}

{% block content %}
<style>
  .glyphicon {
    cursor: crosshair;
  }
</style>

<h2>User submissions</h2>

<ul class="game-list">
  {% for submission in submissions %}
    <li>
      <p>
        <strong>{{ submission }}</strong>
      </p>
      <p>
        <span class="small">
          {{submission.revision.user}}
          {{submission.revision.date_created}}
        </span>
      </p>
    </li>
  {% endfor %}
</ul>


<h2>User drafts</h2>

<ul class="game-list">
  {% for submission in drafts %}
    <li>
      <p>
        <strong>{{ submission }}</strong>
      </p>
      <p>
        <span class="small">
          {{submission.revision.user}}
          {{submission.revision.date_created}}
        </span>
      </p>
    </li>
  {% endfor %}
</ul>

<h2>Unpublished installers</h2>
<ul class="game-list">
{% for installer in installers %}
<li>
  <p>
    <strong>{{installer.game}}</strong>
  </p>
  <p>
    <span class="small">
      {{installer.user}}
      {{installer.created_at}}
    </span>
  </p>
</li>
{% endfor %}
</ul>

<h2>Unpublished games with installers</h2>
<ul class='game-list'>
  {% for game in unpublished_games %}
  <li>
    <p>
      <strong>{{game}}</strong>
      <span>
        <a href="{% url 'game_detail' slug=game.slug %}" class="btn">Review</a>
      </span>
    </p>
  </li>
  {% endfor %}
</ul>

{% endblock %}
